﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using LiveCPEWinForm.LiveCPEWS;
using LiveCPEWinForm.Gestionnaire;

namespace LiveCPEWinForm.comp
{
    public partial class CsComment : UserControl
    {
        private CommentWS lComment;
        private GestAPP lGestAPP;
        public CsComment(GestAPP pGestAPP, CommentWS pComment)
        {
            InitializeComponent();
            // Recup du comment
            lComment = pComment;
            lGestAPP = pGestAPP;
            // Initialisation du controle
            InitComment();

        }
        private void InitComment()
        {
            lblUser.Text = "(" + lComment.AuthorName + ")";
            lblMessage.Text = lComment.CommentContent;
            lblHeurePost.Text = "Published on " + Convert.ToString(lComment.PublicationDate);
            lblNBLike.Text = Convert.ToString(lComment.NumLike);
            // Image
            foreach (UserWS user in lGestAPP.GestFriends.ListFriend)
            {
                if (user.UserName.ToLower() == lComment.AuthorName.ToLower())
                {

                    if (user.Picture.Length > 0)
                    {
                        try
                        {

                            System.IO.MemoryStream ms = new System.IO.MemoryStream(user.Picture);
                            pbProfile.Image = System.Drawing.Image.FromStream(ms);
                        }
                        catch (Exception) { }
                    }
                }
            }
            foreach (UserWS user in lGestAPP.GestFriends.ListNoFriend)
            {
                if (user.UserName.ToLower() == lComment.AuthorName.ToLower())
                {

                    if (user.Picture.Length > 0)
                    {
                        try
                        {

                            System.IO.MemoryStream ms = new System.IO.MemoryStream(user.Picture);
                            pbProfile.Image = System.Drawing.Image.FromStream(ms);
                        }
                        catch (Exception) { }
                    }
                }
            }
        }

        private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            lGestAPP.LikeComment(Convert.ToString(lComment.CommentID));
            (sender as LinkLabel).Visible = false;
        }

        private void CsComment_Load(object sender, EventArgs e)
        {

        }
    }
}
